package com.app.business.service;

import com.app.business.model.ShopHouseBuyPerson;
import com.app.system.jpa.JpaBaseDao;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 店面产权人信息业务层
 * Created by szy on 2024/5/13
 */
@Service
@SuppressWarnings("all")
public class ShopHouseBuyPersonService extends JpaBaseDao<ShopHouseBuyPerson,Integer> {

    /**
     * 通过店面id得到ShopHouseBuyPerson中的产权人id
     * @param ShopHouseId
     * @return
     */
    @Transactional
    public List<String> getBuyHousePersonIdListByShopHouseId(Integer shopHouseId) {
        String sql = "select buy_house_person_id from shop_house_buy_person  where shop_house_id =:shopHouseId";
        return this.entityManager.createNativeQuery(sql).setParameter("shopHouseId", shopHouseId).getResultList();
    }

    @Transactional
    public List<Integer> getBuyHousePersonIdListByShopHouseIdForInteger(Integer shopHouseId) {
        String sql = "select buy_house_person_id from shop_house_buy_person  where shop_house_id =:shopHouseId";
        return this.entityManager.createNativeQuery(sql).setParameter("shopHouseId", shopHouseId).getResultList();
    }


    /**
     * 通过shopHouseId删除店面关联的产权人
     * @param shopHouseId
     */
    @Transactional
    public synchronized void deleteShopHouseBuyPersonByShopHousetId(Integer shopHouseId) {
        //查询语句
        String sql = "delete from shop_house_buy_person  where shop_house_id =:shopHouseId";
        this.entityManager.createNativeQuery(sql).setParameter("shopHouseId",shopHouseId).executeUpdate();
    }
    /**
     * 通过buyShopHouseId删除店面关联的产权人
     * @param shopHouseId
     */
    @Transactional
    public synchronized void deleteShopHouseBuyPersonByBuyHousePersonId(Integer buyHousePersonId) {
        //查询语句
        String sql = "delete from shop_house_buy_person  where buy_house_person_id =:buyHousePersonId";
        this.entityManager.createNativeQuery(sql).setParameter("buyHousePersonId",buyHousePersonId).executeUpdate();
    }
}
